package com.example.gyj.util;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * Md5Util
 * @author Gao
 * @date 2018/10/20
 */
public class Md5Util {

    private static final String salt = "1a2b3c4d";

    public static String md5(String str) {
        return DigestUtils.md5Hex(str);
    }

    public static String inputPassToFromPass(String inputPass) {
        String str = "" + salt.charAt(0) + salt.charAt(1) + inputPass + salt.charAt(2) + salt.charAt(3);
        return md5(str);
    }

    public static String fromPassToDBPass(String fromPass, String salt) {
        String str = "" + salt.charAt(0) + salt.charAt(1) + fromPass + salt.charAt(2) + salt.charAt(3);
        return md5(str);
    }

    public static String inputPassToDBPass(String inputPass, String saltDB) {
        String fromPass = inputPassToFromPass(inputPass);
        String dbPass = fromPassToDBPass(fromPass, saltDB);

        return dbPass;
    }

    public static void main(String[] args) {
        //System.out.println(inputPassToFormPass("123456"));
        //System.out.println(inputPassToDBPass("123456", "1a2b3c"));
    }
}
